package chapter13;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-03-23 下午4:02
 */
public class SetTest {
    public static void main(String[] args) {
        Set<String> set = new HashSet<>();
        set.add("test1");
        set.add("test2");
        set.add("test3");
        set.add("test3");
        set.forEach(System.out::println);
        Iterator<String> st = set.iterator();
        while (st.hasNext()) {
            String temp = st.next();
            if ("test2".equals(temp)) {
                st.remove();
            }
        }
        System.out.println("----- after remove ----");
        set.forEach(System.out::println);

        System.out.println("----- tree set ----");
        Set<String> treeSet = new TreeSet<>();
        treeSet.add("test4");
        treeSet.add("aest35");
        treeSet.add("test3");
        treeSet.add("test17");
        treeSet.forEach(System.out::println);


        Set<Book> books = new TreeSet<>();
        books.add(new Book("test1", 12.3));
        books.add(new Book("test1", 12.3));
        books.add(new Book("test2", 12.3));
        books.add(new Book("test3", 14.3));
        books.forEach(System.out::println);

        System.out.println("---- iterator ----");
        Iterator<Book> iterator = books.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next().toString());
        }
    }
}
